﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace The_LarX
{
    public class InterpreterMethodCollection
    {
        /// <summary>
        /// The various forms of the same method
        /// </summary>
        public InterpreterMethod[] Methods;

        public InterpreterMethodCollection()
        {
        }

        /// <summary>
        /// Simply call the Correct method depending on Arguments size
        /// </summary>
        /// <param name="args"></param>
        public void CallCorrectMethod(InterpreterArguments args)
        {
            if (Methods != null)
            {
                for (int i = 0; i < Methods.Length; i++)
                {
                    int NumberOfAccepted = 0;
                    for (int k = 0; k < Methods[i].RequiredArgumentsTypes.Length; k++)
                    {
                        if (Methods[i].RequiredArgumentsTypes[k] == args.Values[k].GetType())
                        {
                            NumberOfAccepted++;
                        }
                    }
                    if (NumberOfAccepted == Methods[i].RequiredArgumentsTypes.Length)
                        Methods[i].Do(args);
                }
            }
        }
    }
}
